import { computed } from 'vue'

/**
 * 获取年份范围集合
 * @param {number} startYear - 起始年份（默认2023）
 * @param {Date} [endDate] - 截止日期（默认当前日期）
 * @returns {Array<{label: string, start: string, end: string, value: string}>}
 */
function getYearRanges(startYear = 2023, endDate = new Date()) {
    const years = []
    const endYear = endDate.getFullYear()

    for (let year = startYear; year <= endYear; year++) {
        years.push({
            label: `${year}年`,
            start: `${year}-01-01`, // 每年第一天
            end: `${year}-12-31`, // 每年最后一天
            value: String(year), // 用年份作为唯一值
        })
    }

    return years.reverse()
}

export default function useYearRanges(startYear = 2023) {
    const yearRanges = computed(() => getYearRanges(startYear))

    // 获取当前年份信息
    const currentYear = computed(() => {
        const year = new Date().getFullYear() - 1
        return {
            label: `${year}年`,
            value: String(year),
        }
    })

    return { yearRanges, currentYear }
}
